<?php
	
	namespace Aspic;
	
	class Mail extends Std {
		
		// to, subject, body, headers (content-type..)
		
		public function __construct() {
			parent::__construct();
		}
		
		public function send() {
			if(!preg_match('#^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$#iD', $this->to)) {
				return false;
			}
			else {
				$sended = mail($this->to, $this->subject, $this->body, $this->getHeadersStr());
			
				return $sended;
			}
		}
		
		protected function getHeadersStr() {
			$headers = $this->_vars;
			$notHeader = array(
				'body', 'to', 'subject'
			);
			
			foreach($notHeader as $name) {
				unset($headers[$name]);
			}
			
			$arrheadersStr = array();
			
			foreach($headers as $k => $v) {
				$arrheadersStr[] = $k.': '.$v;
			}

			$str = implode("\r\n", $arrheadersStr);
			
			return $str;
		}
		
	}	
	
?>